//
//  Status.swift
//  SwiftWeibo
//
//  Created by Lucky on 16/5/23.
//  Copyright © 2016年 Lucky. All rights reserved.
//

import UIKit

class Status: NSObject {
    /// 微博ID
    var id: Int = 0
    
    /// 微博创建时间
    var created_at: String?
    
    /// 微博内容
    var text: String?
    
    /// 微博来源
    var source: String?
    
    /// 配图数组
    var pic_urls: [[String: AnyObject]]?
    
    // MARK: - 加载微博数据
    class func loadStatuses(success: (models: [Status])->(), failure: (error: NSError)->()) {
        let params = ["access_token": UserAccount.loadAccount()!.access_token!]
        NetworkTools.shareNetworkTools().GET("2/statuses/home_timeline.json", parameters: params, success: { (_, JSON) in
            print(JSON)
            
            let models = dictToModel(JSON!["statuses"] as! [[String: AnyObject]])
            
            success(models: models)
            
            }) { (_, error) in
                print(error)
                failure(error: error)
        }
    }
    
    class func dictToModel(list: [[String: AnyObject]]) -> [Status] {
        var models = [Status]()
        for dict in list {
            models.append(Status(dict: dict))
        }
        return models
    }
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    var properties = ["id", "created_at", "text", "source", "pic_urls"]
    
    override var description: String {
        let dict = dictionaryWithValuesForKeys(properties)
        return "\(dict)"
    }
}
